import QtQuick 1.0
import com.nokia.symbian 1.0

Page {
    id: mainPage
    tools: toolBarMainPage

    function openFile(file) {
        var component = Qt.createComponent(file)
        if (component.status == Component.Ready)
            pageStack.push(component);
        else
            console.log("Error loading component:", component.errorString());
    }

    ListModel {
        id: pagesModel

        ListElement {
            page: "Page1.qml"
            title: "Navigation"
            subtitle: "Navigation Example"
        }
        ListElement {
            page: "Page2.qml"
            title: "Music Player"
            subtitle: "Music player Example"
        }
        ListElement {
            page: "Page3.qml"
            title: "NFC"
            subtitle: "NFC Example"
        }
        ListElement {
            page: "Page4.qml"
            title: "Gallery"
            subtitle: "Gallery Example"
        }
        ListElement {
            page: "Page5.qml"
            title: "Game"
            subtitle: "Game Example"
        }
        ListElement {
            page: "Page6.qml"
            title: "NFC Peer-to-Peer"
            subtitle: "NFC Peer-to-Peer Example"
        }
    }

    ListView {
        id: listView
        anchors.fill: parent
        model: pagesModel

        delegate:  Item {
            id: listItem
            height: platformStyle.graphicSizeLarge
            width: parent.width

            Row {
                anchors.fill: parent

                Column {
                    anchors.verticalCenter: parent.verticalCenter
                    spacing: platformStyle.paddingSmall

                    Text {
                        id: mainText
                        text: model.title
                        font {
                             family: platformStyle.fontFamilyRegular
                             pixelSize: platformStyle.fontSizeLarge
                        }
                        color: platformStyle.colorNormalLight
                    }

                    Text {
                        id: subText
                        text: model.subtitle
                        font {
                            family: platformStyle.fontFamilyRegular
                            pixelSize: platformStyle.fontSizeSmall
                        }
                        color: platformStyle.colorNormalMid
                    }
                }
            }

            Image {
                source: "image://theme/toolbar-next"
                anchors.right: parent.right;
                anchors.verticalCenter: parent.verticalCenter
            }

            MouseArea {
                id: mouseArea
                anchors.fill: parent
                onClicked: {
                    mainPage.openFile(page)
                }
            }
        }
    }

    ScrollDecorator {
        flickableItem: listView
    }

    ToolBarLayout {
        id: toolBarMainPage
        ToolButton {
            flat: true
            iconSource: "toolbar-back"
            onClicked: pageStack.depth <= 1 ? Qt.quit() : pageStack.pop()
        }
    }
}
